package agent

import (
	"context"

	"gitee.com/liuxuezhan/ar-platform/rpc-client/agentClient/rpc"
	"github.com/zeromicro/go-zero/core/logc"

	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/svc"
	"gitee.com/liuxuezhan/ar-platform/admin-api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetRebatesLevelManagerListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetRebatesLevelManagerListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetRebatesLevelManagerListLogic {
	return &GetRebatesLevelManagerListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetRebatesLevelManagerListLogic) GetRebatesLevelManagerList() (resp *types.RebatesLevelManagerList, err error) {
	// 返佣等级管理--列表
	rpcReq := rpc.RebatesLevelManagerListReq{}
	rpcResp, err := l.svcCtx.AgentRPC.GetRebatesLevelManagerList(context.Background(), &rpcReq)
	if err != nil {
		logc.Error(l.ctx, err)
		return nil, err
	}

	_data := make([]types.RebatesLevelManagerInfo, len(rpcResp.Data))
	for _i, _row := range rpcResp.Data {
		_detail := make([]types.RebatesConditionCount, len(_row.RebatesConditionCount))
		for _j, _v := range _row.RebatesConditionCount {
			_detail[_j] = types.RebatesConditionCount{
				ConditionType:  _v.ConditionType,
				ConditionValue: _v.ConditionValue,
				Count:          _v.Count,
			}
		}
		_data[_i] = types.RebatesLevelManagerInfo{
			Level: _row.Level,
			// CreatedAt: _row.CreatedAt,
			Count:   _row.Count,
			CountAt: _row.CountAt,
			Remark:  _row.Remark,
			Detail:  _detail,
		}
	}
	resp = &types.RebatesLevelManagerList{
		List: _data,
	}

	return
}
